
capture log close
log using $log/EDS_05_balacning_02, text replace

clear
clear matrix
clear mata
set mem 2g
set matsize 800
set more off
set maxvar 20000
set trace off
set varabbrev off


forvalues spec = 1/2 {

use $data/data_pair,clear

 

#d;
	  global educ " _Isu_schule_1 _Isu_schule_2 _Isu_schule_3 
          _Isu_ausbila1 _Isu_ausbila2
		  write_ger speak_ger write_eng speak_eng
	  ";
    
	  global basevar "female 
          german migration_background 
          _Isu_kat_al_2 _Isu_kat_al_3 _Isu_kat_al_4 
          married  _Ichild_1 _Ichild_2
		  	homeowner _Idauloint__8 _Idauloint__9 _Idauloint__10 _Idauloint__11 _Idauloint__12 
          _Idauloint__13 _Idauloint__14  
		  ";
	
	  global history "benefit_status benefit_level log_benefit_level
    lifetime_ue_age lifetime_empl_age last_wage last_wage_mis 
            _Ibefstat_1 _Ibefstat_2 _Ibefstat_3 _Ibefstat_4
	    	
	  ";
	
	    global macrovars "region_ba_aloq_zivall gdp_real_pc region_ba_vacancies 
	   sector_manufacturing sector_service  log_mobirate_avg5
	   _Isu_eintri_1 _Isu_eintri_2 _Isu_eintri_3 _Isu_eintri_4 _Isu_eintri_5
	  _Isu_eintri_6 _Isu_eintri_7 _Isu_eintri_8 _Isu_eintri_9 _Isu_eintri_10 _Isu_eintri_11
       east_germany";
	   
	   
	   
	    	
	  
	   global traits "openness_st conscient_st extraversion_st neuroticism_st loc_st
	    ";
     
	   #d cr
    
		
	 use $data/data_pair, clear
	  
	  
	  	gen bula = floor(region_kkz/1000)
		tab bula, g(bula_)
	  
	  
	   if `spec'==1 {
	   local ivres "log_intensity_alt"
	   bys pers_id: keep if _n==1
	 qui  reg `ivres' $educ $basevar $history $traits ,cluster(region)
	  }
	  
	
		 if `spec'==2 {
	qui reg log_intensity_alt $macrovars county_pair_* [pw=1/fweight_reg] , cluster(region)
	  
	  estimates store macro_spec`spec'
	  predict residual_spec`spec', r
	  local ivres "residual_spec`spec'"
	 qui reg `ivres' $educ $basevar $history $traits  county_pair_* [pw=1/fweight_reg] , cluster(region)
		}
		
	   
	  
	  test $educ
	  estadd scalar pvalue_educ=r(p)
		
	  test $basevar
	  estadd scalar pvalue_basevar=r(p)
	  
	  test $history
	  estadd scalar pvalue_history=r(p)
		
	  test $traits
	  estadd scalar pvalue_traits=r(p)
		estimates store est_`spec'
	  matrix r`spec'=e(r2)
	 
	  
	  
	  }
		#d;
		esttab est_1 est_2  
		using $data/Table_A4.tex,
		label b(3) se(3) wide replace 
		mtitles ("(1) Unconditional" "(2) Conditional A" "(3) Conditional B" )
		scalars(
		"ftest_educ F-test of joint significance educ"
		"pvalue_educ \quad $p-$value educ"
		
		"ftest_basevar F-test of joint significance basevar"
		"pvalue_basevar \quad $p-$value basevar"

		
		"ftest_history F-test of joint significance history"
		"pvalue_history \quad $p-$value history"
		
		"ftest_traits F-test of joint significance traits"
		"pvalue_traits \quad $p-$value traits"
		
		"r2 R^2"
		)
		 starlevels("$^{*}$" 0.1 "$^{**}$" 0.05 "$^{***}$" 0.01)
	   refcat(
	   _Isu_kat_al_2 "Age (Ref.: 16-24 years)"
	   _Isu_schule_1 "School leaving degree (Ref.: None)"
	   _Isu_ausbila1 "Higher education (Ref.: None)"
	   _Ichild_1 "Children (Ref.: None)"
	  _Ibefstat_1 "Employment status before UE (Ref.: Other)"
	     )
		 drop(county_pair_*);
	   
	   #d cr
	   
	   
	  
		log close
	 
	

